import * as constants from './constants';
import axios from 'axios';
import { fromJS } from 'immutable'
const headerList = (data) => ({
    type: constants.header_List,
    data: fromJS(data),
    //Math.ceil向上取整  
    totalPage: Math.ceil(data.length / 10)
})
export const searchFocus = () => ({
    type: constants.search_focus
})
//此处是一个箭头函数去return一个对象出来的简写方式
export const searchBlurd = () => ({
    type: constants.search_Blurd
})
export const mouseEnter = () => ({
    type: constants.mouse_Enter
})
export const MouseLeave = () => ({
    type: constants.Mouse_Leave
})
export const ChangePage = (page) => ({
    type: constants.Change_Page,
    page
})
export const getList = () => {
    return (dispatch) => {
        axios.get('/api/headList.json').then((res) => {
            res = res.data;
            if (res.success === true) {
                // console.log(res);
                dispatch(headerList(res.data))
            }

        }).catch(() => {
            console.log('错误')
        })
    }
}